<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Test extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('m_giaodien');
        $this->load->helper(array('form', 'url'));
        $x = "";
    }

    function index() {
        $data['header'] = $this->m_giaodien->getValue(1);
        $data['logo'] = $this->m_giaodien->getValue(2);
        $data['x'] = $x;
        $this->load->view('test', $data);
    }

    function get_version() {

        echo CI_VERSION; // echoes something like 1.7.1
    }

    function forward() {
        if ($this->input->post('accept') != '') {
            $this->header_upload();
            //redirect('/test', 'refresh');
        } else if ($this->input->post('cancel') != '') {
            redirect('/test', 'refresh');
        }
    }

    function x() {
        echo $this->input->post('name');
    }

    function header_upload() {
        $config['upload_path'] = './assets/imgs/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '2000';
        $config['max_height'] = '2000';

        $this->load->library('upload', $config);
        echo 'pre up';
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            echo 'error';
            $this->load->view('test', $error);
        } else {
            $upload_data = $this->upload->data();
//
            $HinhAnh = 'imgs/' . $upload_data['file_name'];

            $data = array(
                'Value_element' => $HinhAnh,
            );
            print_r($data);
//            echo 'pass pre-update';
            if ($this->m_giaodien->updateImage(1, $data))
                redirect('/test', 'refresh');
        }
    }

    function logo_upload() {
        $config['upload_path'] = './assets/imgs/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '900';
        $config['max_height'] = '181';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('test', $error);
        } else {
            $upload_data = $this->upload->data();
            $HinhAnh = 'imgs/' . $upload_data['file_name'];
            $data = array(
                'HinhAnh' => $HinhAnh,
            );
            $this->m_giaodien->updateImage(2, $data);
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */